<%@ taglib uri="http://www.rapid-framework.org.cn/rapid" prefix="rapid"%>
<%@ page language="java" import="java.util.*"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<rapid:override name="frame-header-style">
	<link rel="stylesheet" href="resources/css/index-page.css">
</rapid:override>

<rapid:override name="frame-header-script">
	<script type="text/javascript" src="resources/js/jquery.min.js"></script>
	<script>
		$(function() {
			
			//linkName
			$("#linkName").blur(linkNam);
			function linkNam(){
				var r=false;
				var reg=/^[^\s]{1,20}$/;
				if( !reg.test($("#linkName").val()) ){
					$("#linkName_msg").html("链接名不合法.请输入1-20位字符");
					return r;
				}
				$.ajax({
					url:"link/yzLinkName",
					type:"POST",
					data:{linkName:$("#linkName").val()},
					async:false,
					cache:false,
					dataType:"text",
					success:function(str){
						if(str==0){//没有该名字
							$("#linkName_msg").html("");
							r=true;
						}else{
							$("#linkName_msg").html("该名称已被占用");
						}
					}
				});
				return r;
			}
			
			//linkUrl
			$("#linkUrl").blur(linkUr);
			function linkUr(){
				var r=false;
				var reg=/^[^\s]{1,20}$/;
				if( !reg.test($("#linkUrl").val()) ){
					$("#linkUrl_msg").html("url不合法.请输入1-20位");
				}else{
					$("#linkUrl_msg").html("");
					r=true;
				}
				return r;
			}
			
			//linkOrder
			$("#linkOrder").blur(linkOrde);
			function linkOrde(){
				var r=false;
				var reg=/^[0-9]{1,3}$/;
				if( !reg.test($("#linkOrder").val()) ){
					$("#linkOrder_msg").html("order不合法.请输入1-3位数字");
				}else{
					$("#linkOrder_msg").html("");
					r=true;
				}
				return r;
			}
			
			//submit
			$("#subm").click(function(){
				var r=true;
				
				if(!linkNam()){
					r=false;
				}
				
				if(!linkUr()){
					r=false;
				}
				
				if(!linkOrde()){
					r=false;
				}
				
				if(r){
					r=confirm("确定修改该链接吗");
				}
				return r;
			});

		});
	</script>
</rapid:override>

<rapid:override name="frame-content">
	<!-- 内容主体区域 -->
	<div style="padding: 15px;">
		<blockquote class="layui-elem-quote">
			<span class="layui-breadcrumb" lay-separator="/"> 
				<a href="Login">首页</a> <a href="link/linkList">链接列表</a> <a><cite>添加链接</cite></a>
			</span>
		</blockquote>
		<div class="layui-row">
			<div class="layui-col-md4">
				<form class="layui-form" method="post" id="myForm" action="link/updateLink">
					<input name="linkId" value="${link.linkId }" />
					<div class="layui-form-item">
						<div class="layui-input-block">
							<strong>编辑链接</strong>
						</div>
						<input type="hidden" name="linkId" value="">
						<div class="layui-input-block">
							名称 <span style="color: #FF5722;" id="linkName_msg">*</span> 
							<input type="text" name="linkName" id="linkName" value="${link.linkName }" autocomplete="off" class="layui-input" required>
						</div>
						<br>
						
						<div class="layui-input-block">
							URL <span style="color: #FF5722;" id="linkUrl_msg">*</span> 
							<input type="text" name="linkUrl" id="linkUrl" value="${link.linkUrl }" autocomplete="off" class="layui-input" required>
						</div>
						<br>
						
						<div class="layui-input-block">
							联系方式 <input type="text" name="linkOwnerContact" value="${link.linkOwnerContact }" autocomplete="off" class="layui-input">
						</div>
						<br>
						
						<div class="layui-input-block">
							描述 <input type="text" name="linkDescription" value="${link.linkDescription }" autocomplete="off" class="layui-input">
						</div>
						<br>
						
						<div class="layui-input-block">
							Order <span style="color: #FF5722;" id="linkOrder_msg">*</span> 
							<input type="number" name="linkOrder" id="linkOrder" value="${link.linkOrder }" autocomplete="off" class="layui-input" min="0" max="10">
						</div>
						<br>
						
						<div class="layui-input-block">
							<button class="layui-btn" lay-filter="formDemo" id="subm" type="submit">修改</button>
						</div>
					</div>
				</form>
				<blockquote class="layui-elem-quote layui-quote-nm">
					温馨提示：
					<ul>
						<li>URL：如 http://liuyanzhao.com</li>
						<li>Order：默认是0，Order越大排名越靠前</li>
					</ul>
				</blockquote>
			</div>
			<div class="layui-col-md8">
				<table class="layui-table">
					<colgroup>
						<col width="50">
						<col width="300">
						<col width="100">
						<col width="50">
						<col width="100">
					</colgroup>
					<thead>
						<tr>
							<th>id</th>
							<th>名称</th>
							<th>URL</th>
							<th>Order</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						
						<c:forEach var="l" items="${linkList }">
							<tr>
								<td>${l.linkId }</td>
								<td>${l.linkName }</td>
								<td>${l.linkUrl }</td>
								<td>${l.linkOrder }</td>
								<td>
									<a href="link/edit/${l.linkId }" class="layui-btn layui-btn-mini">编辑</a> 
									<a href="link/delete/${l.linkId }" class="layui-btn layui-btn-danger layui-btn-mini" onclick="return confirmDelete()">删除</a>
								</td>
							</tr>
						</c:forEach>
	
					</tbody>
				</table>
			</div>
		</div>
	</div>
</rapid:override>

<%@ include file="../framework.jsp"%>